package com.projet.instamiam;

import java.util.Arrays;

import com.projet.instamiam.GalleryAdapter;

import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;
import android.view.View;

public class MainActivity extends Activity implements OnItemClickListener{
	
	public  GridView gridview;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);	
		
		Uri baseUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
		Cursor c = getContentResolver().query( baseUri,new String[] {MediaStore.Images.Media._ID }, null, null, null);
		
		this.gridview = (GridView) findViewById(R.id.gridview);
		gridview.setAdapter(new GalleryAdapter(this,c));
		
		gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            	//Toast.makeText(MainActivity.this,, Toast.LENGTH_SHORT).show();
            	//System.out.println(gridview.getSelectedItem());
            	Intent intent = new Intent(MainActivity.this, AnnotationActivity.class);
            	intent.putExtra("com.projet.instamiam.message", id);
            	MainActivity.this.startActivity(intent);
            }
        });
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		Toast.makeText(this.getApplicationContext(),"Test", Toast.LENGTH_LONG).show();
	}

}
